<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Jedrzej\Pimpable\PimpableTrait;

class MemberCard extends Model
{

    use HasFactory;
    use PimpableTrait;


    /**
     * 默认排序
     */
    protected $defaultSortCriteria = ['id,desc'];

    /**
     * 可排序字段
     */
    public $sortable = [
        'created_at',
        'id',
        'card_batch_id',
        'card_number',
        'use_time',
    ];

    /**
     * 可搜索字段
     */
    public $searchable = [
        'card_batch_id',
        'card_number',
        'user_id',
        'use_time',
        'work_id',
        'created_at',
    ];
    /**
     * 会员卡表可批量赋值字段
     */
    protected $fillable =[
        'card_number',
        'card_batch_id',
        'card_password',
        'user_id',
        'use_time',
        'status',
    ];
    /**
     * 会员卡所属批次
     */
    public function batch(){
        return $this->belongsTo(MemberCardBatch::class,'card_batch_id','id');
    }

     /**
      * 会员卡所属用户
      */
     public function user(){
         return $this->belongsTo(User::class,'user_id','id');
     }

}
